package cn.gxa.edu_adm.service.impl;

import cn.gxa.edu_adm.bean.Admin;
import cn.gxa.edu_adm.commn.model.ResultCodeEnum;
import cn.gxa.edu_adm.commn.model.ResultData;
import cn.gxa.edu_adm.dao.AdminDao;
import cn.gxa.edu_adm.dao.impl.AdminDaoImpl;
import cn.gxa.edu_adm.service.AdminService;
import cn.gxa.edu_adm.utils.MD5Utils;

import java.util.HashMap;

/**
 * 业务层的实现类  实现类
 */
public class AdminServiceImpl implements AdminService {
    private AdminDao adminDao =new AdminDaoImpl();
    @Override
    public ResultData checkLogin(String username, String password) {
        //加盐操作 (现在好多网站可以破解MD5 对比)
        password="gxa@."+password+"gxa@.";
        //密码加密 利用MD5进行加密
        password=MD5Utils.md5(password);
        //数组组装 给service
        Admin  admin=adminDao.checkLogin(username,password);
        if(admin==null){
            return  ResultData.error(ResultCodeEnum.LOGIN_ERROR);
        }
        return ResultData.ok(ResultCodeEnum.LOGIN_SUCCESS).data(admin);//  User | null
    }

    @Override
    public ResultData updateHeadImg(Integer userId, String filePath) {
        if(adminDao.updateHeadImg(userId,filePath)>0) {
            HashMap<String, String> path = new HashMap<>();
            path.put("src", filePath);
            return ResultData.ok(ResultCodeEnum.FILE_UPLOAD_SUCCESS).data(path);
        }
        return  ResultData.error();
    }

    @Override
    public ResultData updatePassword(Integer userId, String oldPassword, String newPassword) {
        return null;
    }
}
